const path = require('path');
const { app, BrowserWindow } = require('electron');
const express = require('express');
const httpServer = express();
const pkg = require('./package.json');

// 加载IPC
require('./ipc');

function createWindow() {
    let win = new BrowserWindow({
        width: 1000,
        height: 815,
        webPreferences: {
            javascript: true,
            plugins: true,
            nodeIntegration: true,
            webSecurity: false
        }
    });

    if(pkg.DEV){
        win.loadURL("http://localhost:3000/");
    }else{
        httpServer.use(express.static(path.join(__dirname, './build/')));
        httpServer.listen(8888, () => {
            win.loadURL("http://localhost:8888/index.html");
        });
    }

    win.on('closed', () => {
        win = null;
    });
}

app.on('ready', createWindow);

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
        app.quit();
    }
});